package com.hs.server.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.hs.server.domain.VehZnshdazpxx;
import com.hs.server.domain.VehZnshzlzpxx;
import com.hs.server.exception.GlobalException;
import com.hs.server.mapper.VehZnshdazpxxMapper;
import com.hs.server.service.VehZnshdazpxxService;
import org.apache.commons.lang3.StringUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

/**
 * @Description
 * @Author: chenjiarui
 * @Date: 2021-07-09 9:22
 */
@Service
public class VehZnshdazpxxSerivceImpl implements VehZnshdazpxxService {
    @Autowired
    VehZnshdazpxxMapper vehZnshdazpxxMapper;

    @Override
    public VehZnshdazpxx GetVehZnshdazpxx(String lsh) {
        if(StringUtils.isBlank(lsh)){
            throw new GlobalException("流水号不能为空");
        }
        return vehZnshdazpxxMapper.selectById(lsh);
    }

    @Override
    public synchronized int AddVehZnshdazpxx(VehZnshdazpxx vehZnshdazpxx) {
        QueryWrapper<VehZnshdazpxx> qw = new QueryWrapper<>();
        qw.eq("lsh",vehZnshdazpxx.getLsh());
        qw.eq("lb",vehZnshdazpxx.getLb());
        if (vehZnshdazpxxMapper.selectCount(qw)==0)
             return vehZnshdazpxxMapper.insert(vehZnshdazpxx);
        else
            return vehZnshdazpxxMapper.update(vehZnshdazpxx,qw);
    }
}
